/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.asik.soapPlayground.soap.endpoint;

import java.text.SimpleDateFormat;
import java.util.Date;
import javax.lang.model.element.Element;
import net.asik.soapPlayground.soap.service.HumanResourceService;
import org.jdom.JDOMException;
import org.jdom.xpath.XPath;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.Namespace;
import org.springframework.ws.server.endpoint.annotation.Namespaces;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.XPathParam;
import org.springframework.ws.soap.SoapBody;
import org.springframework.ws.soap.SoapHeader;

/**
 *
 * @author asikprad
 */
@Endpoint
public class HolidayEndpoint {

    private static final String NAMESPACE_URI = "http://mycompany.com/hr/schemas";
    private XPath startDateExpression;
    private XPath endDateExpression;
    private XPath nameExpression;
    private HumanResourceService humanResourceService;

    public HolidayEndpoint()
            throws JDOMException {
        this.humanResourceService = new HumanResourceService();
/*
        org.jdom.Namespace namespace = org.jdom.Namespace.getNamespace("hr", NAMESPACE_URI);

        startDateExpression = XPath.newInstance("//hr:StartDate");
        startDateExpression.addNamespace(namespace);

        endDateExpression = XPath.newInstance("//hr:EndDate");
        endDateExpression.addNamespace(namespace);

        nameExpression = XPath.newInstance("concat(//hr:FirstName,' ',//hr:LastName)");
        nameExpression.addNamespace(namespace);
*/
    }

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "HolidayRequest")
    public void handleHolidayRequest(SoapBody body, SoapHeader header)
            throws Exception {
        System.out.println("body: "+ body.toString());

      //  humanResourceService.bookHoliday(startDate, endDate, name);
    }

    @PayloadRoot(localPart = "orderRequest", namespace = NAMESPACE_URI)
    @Namespace(prefix = "s", uri = NAMESPACE_URI)
    public String getOrder(@XPathParam("//hr:FirstName") String name) {
        return humanResourceService.printName(name);
        // create Source from order and return it
    }
}
